#include<iostream>
#include<signal.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
using namespace std;
void handler(int signo)
{
    cout<<"我们的进程确实收到了："<<signo<<endl;
    //exit(1);
}
void ShowBlock(sigset_t *oset)
{
    int signo=1;
    for(;signo<=32;signo++)
    {
        if(sigismember(oset,signo))cout<<"1";
        else cout<<"0";
    }
    cout<<endl;
    
}
int main()
{
    //在用户层面上进行设置
    sigset_t set,oset;
    sigemptyset(&set);
    sigemptyset(&oset);
    sigaddset(&set,2);
    //设置就进入进程，谁调用，设置谁
    sigprocmask(SIG_SETMASK,&set,&oset);
    int cnt=0;
    while(true)
    {
        ShowBlock(&oset);
        sleep(1);
    }
    return 0;
}
int main1()
{
    pid_t id=fork();
    if(id==0)
    {
        sleep(2);
        cout<<"野指针问题...here"<<endl;
        cout<<"野指针问题...here"<<endl;
        cout<<"野指针问题...here"<<endl;
        int *p=nullptr;
        *p=100;

        cout<<"野指针问题...here"<<endl;
        cout<<"野指针问题...here"<<endl;
        cout<<"野指针问题...here"<<endl;
        exit(0);
    }
    int status=0;
    waitpid(id,&status,0);
    cout<<"exit code"<<((status>>8)&0xFF)<<endl;
    cout<<"exit signal"<<(status&0x7F)<<endl;
    cout<<"core dump"<<((status>>7)&0x1)<<endl;
    //signal(SIGSEGV,handler);
    //int*p=nullptr;
    //*p=10;
    //cout<<"野指针问题...here"<<endl;
    //int a=10;
    //a/=0;
    //cout<<"div zero ... here"<<endl;
    return 0;
}